const initState = {
    count: 0
}

const actionTypes = {
    INCREMENT: 'INCREMENT',
    DELEREMENT: 'DELEREMENT',
    REST: 'REST'
}

export const actions = {
    increment: () => {
        return {
            type: actionTypes.INCREMENT
        }
    },
    delerement: () => {
        return {
            type: actionTypes.DELEREMENT
        }
    },
    reset: () => {
        return {
            type: actionTypes.REST
        }
    }
}

export const reducer = (state=initState, action) => {
    switch(action.type) {
        case 'INCREMENT':
        state.count ++;
        if(state.count > 10) {
            state.count = 10
        }

        return {
            ...state,
            count: state.count
        }

        case 'DELEREMENT':
        state.count --;
        if(state.count < 0) {
            state.count = 0
        }

        return {
            ...state,
            count: state.count
        }

        case 'REST':
        return {
            ...state,
            count: 0
        }

        default:
        return state
    }
}